---@class Battle.EntityEffectStateSystem: Battle.EntityComponent
local EntityEffectStateSystem = Battle.CreateClass("EntityEffectStateSystem",Battle.EntityComponent)
Battle.EntityEffectStateSystem = EntityEffectStateSystem
function EntityEffectStateSystem:OnCreate()
    --self.totalStateFlag = 0
    --使用引用计数
    self.stateFlagDic = {}
end
---是否可移动
function EntityEffectStateSystem:CanMove()
    if self.actor:IsDead() then return false end
    return not self:HasState(Battle.FighterStateEnum.CAN_NOT_MOVE)
end

---是否可攻击
function EntityEffectStateSystem:CanAttack()
    if self.actor:IsDead() then return false end
    return true
end

function EntityEffectStateSystem:HasState(stateId)
    local count = self.stateFlagDic[stateId] or 0
    return count > 0
end

function EntityEffectStateSystem:AddState(stateId)
    local count = self.stateFlagDic[stateId] or 0
    self.stateFlagDic[stateId] = count + 1
    if count == 0 then
        self.actor.eventSystem:FireEvent(Battle.Event.ActorEffectStateChange,Battle.EventArgs.EntityEffectStateChangeArgs:Create(self.actor,stateId,true))
    end
    --self.totalStateFlag = bit.bor(self.totalStateFlag,stateId)
end
function EntityEffectStateSystem:RemoveState(stateId,isClear)
    local count = self.stateFlagDic[stateId] or 0
    if count == 0 then
        return
    end
    if isClear then
        self.stateFlagDic[stateId] = 0
    else
        self.stateFlagDic[stateId] = count - 1
    end
    if count > 0 and self.stateFlagDic[stateId] == 0 then
        self.actor.eventSystem:FireEvent(Battle.Event.ActorEffectStateChange,Battle.EventArgs.EntityEffectStateChangeArgs:Create(self.actor,stateId,false))
    end
    --self.totalStateFlag = bit.band(self.totalStateFlag,bit.bnot(stateId))
end
function EntityEffectStateSystem:IsHide()
    return self:HasState(Battle.FighterStateEnum.GRASS_HIDE) or self:HasState(Battle.FighterStateEnum.BUFF_HIDE)
end
